<%--

    Copyright (C) 2009 alex <me@alex.0x08.org>

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@ page import="uber.netbsd.community.dao.Role"%>
<%@ page import="uber.netbsd.community.action.ProfileActionBean"%>

<%@ include file="/common/taglibs.jsp" %>

<stripes:layout-render name="/templates/netbsd.jsp" title="Add/Edit User">
    <stripes:layout-component name="contents">


        <stripes:errors/>

        <stripes:form action="/action/Profile" focus="user.username">
            <table class="leftRightForm">
                <tr>
                    <th>User ID:</th>
                    <td>
                        ${empty actionBean.user.id ? "n/a" : actionBean.user.id}
                        <stripes:hidden name="user.id" value=""/>
                    </td>
                </tr>
                <tr>
                    <th><stripes:label for="user.username"/>:</th>
                    <td><stripes:text name="user.username" formatPattern="medium"/></td>
                </tr>
                <tr>
                    <th><stripes:label for="user.firstName"/>:</th>
                    <td><stripes:text name="user.firstName" formatPattern="medium"/></td>
                </tr>
                <tr>
                    <th><stripes:label for="user.lastName"/>:</th>
                    <td><stripes:text name="user.lastName" formatPattern="medium"/></td>
                </tr>
                <tr>
                    <th><stripes:label for="user.email"/>:</th>
                    <td><stripes:text name="user.email" formatPattern="medium"/></td>
                </tr>

                 <tr>
                    <th><stripes:label for="user.password"/>:</th>
                    <td> 
                        <c:choose>
                            <c:when test="${actionBean.user.new}">
                               [Для ввода пароля сохраните пользователя]
                            </c:when>
                            <c:otherwise>
                        <stripes:link href="/action/ChangePassword" event="preEdit" title="Изменить пароль">
                                <c:out value="Изменить пароль"/>
                                <stripes:param name="user.id" value="${actionBean.user.id}"/>
                            </stripes:link>
                                
                            </c:otherwise>
                        </c:choose>
                    </td>
                </tr>

                <tr>
                    <th><stripes:label for="user.roles"/>:</th>
                    <td>



                        <c:forEach var="role" items="${actionBean.user.allRoles}">

                            
                            <stripes:checkbox id="${role.name}"
                                              name="${role.name}"
                                              checked="<%=((ProfileActionBean)pageContext.getRequest().getAttribute("actionBean")).getUser().getRoles().contains((Role)pageContext.getAttribute("role"))%>"
                                              value="true"
                                             />


                            <stripes:label for="role.${role.name}">${role.name}</stripes:label>

                        </c:forEach>

                    </td>
                </tr>

            </table>

            <div class="buttons">
                <stripes:submit name="save" value="Сохранить"/>
                 <stripes:submit name="Delete" value="Удалить" />
                 <stripes:submit name="Back" value="Назад" />

            </div>
        </stripes:form>
    </stripes:layout-component>
</stripes:layout-render>